<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@page import="java.net.URLDecoder"%>
<%@ page import="com.sz.common.SZUtility" %>
<%@page import="com.sz.business.dao.IBusinessDAO"%>

<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


String style1 = "width: 100px;text-align:right;font-size: 12px;";
String style2 = "width: 220px";
String input_text_gray = "width: 220px; color: gray";

String title = "";


String b_name = "";
String b_region_fullname = "";
String b_group_name = "";
String b_tel1 = "";
String b_address = "";
String business_id = "";

String ann_title = "";
String ann_content = "";
String ann_begin_time = "";
String ann_end_time = "";
String ann_state = "";
String ann_type = "";

String ann_begin_time_d = "";
String ann_end_time_d = "";


//模式 	mode_edit 或  mode_add
String mode = request.getParameter("mode");
if(mode.equals("mode_add")) {	
	ServletContext servletContext = request.getSession().getServletContext(); 
	ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
	IBusinessDAO business = (IBusinessDAO) context.getBean("BusinessDAO");
	
	Map map = new HashMap();
	business_id = request.getParameter("business_id");
	map.put("BUSINESS_ID", business_id);
	List list = business.queryBusiness(map);
	if(list != null && list.size() > 0) {
		Map tmp = (Map)list.get(0);
		b_name = SZUtility.toString(tmp.get("NAME"));
		b_region_fullname = SZUtility.toString(tmp.get("REGION_FULLNAME"));
		b_group_name = SZUtility.toString(tmp.get("GROUP_NAME"));
		b_tel1 = SZUtility.toString(tmp.get("TEL1"));		
		b_address = SZUtility.toString(tmp.get("ADDRESS"));
	}
	
	title = "新增商家公告";
	
} else if(mode.equals("mode_edit")) {
	title = "修改商家公告";
}

%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>" target="_self">
		<title><%=title%></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="">
		<meta http-equiv="description" content="" >
	</head>
	
	<body onload="onload()">
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		
		<table width="100%">
		  <tr>
		  	<td colspan="3" class="title0" ><%=title%></td>		  	
	  	  </tr>
	  	</table> 
	  	
	  	<table id = "business_info" width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px;">
	  		<tr>
	  			<th colspan="6" align="left">&nbsp;&nbsp;&nbsp;商家信息</th>
	  		</tr>
	  		<tr>
	  			<td style="<%=style1%>">商家名称&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="b_name" name="b_name" value="<%=b_name%>"  readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">预订电话&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="b_tel1" name="b_tel1" value="<%=b_tel1%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>
	  		<tr>	
	  			<td style="<%=style1%>">区域&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="b_region_fullname" name="b_region_fullname" value="<%=b_region_fullname%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">商圈&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="b_group_name" name="b_group_name" value="<%=b_group_name%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>
	  		
	  		<tr>	  			
	  			<td style="<%=style1%>">地址&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="b_address" name="b_address" value="<%=b_address%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  				  			
	  			<td style="<%=style1%>">商家编号&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="business_id" name="business_id" value="<%=business_id%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>	  		
	  	</table>
	  	
	  	<br/>
	  	
	  	<form name="add_announce_business"  action="announce/addAnnounce.exec" method="post" onsubmit="return check()"> 
	  	<table id = "announce_business" width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px;">
	  		<tr>
	  			<th colspan="4" align="left">&nbsp;&nbsp;&nbsp;公告信息</th>
	  		</tr>
	  		<tr>
	  			<td style="<%=style1%>">公告标题&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="ann_title" name="ann_title" value="<%=ann_title%>" style="<%=style2%>" >	  			
	  			</td>
	  			
	  			<td style="<%=style1%>">公告状态&nbsp;&nbsp;&nbsp;</td>
	  			<td >
	  				<div style="<%=style2%>">
	  				<input type="radio" id="ann_state_1" onclick="onClickRadio_state('1')">有效&nbsp;
	  				<input type="radio" id="ann_state_0" onclick="onClickRadio_state('0')">无效		  			
		  			</div>
	  			</td>	  			
	  		</tr>
	  		
	  		<tr>
	  			<td style="<%=style1%>">公告内容&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<textarea id="ann_content" name="ann_content" style="width:300px; height:100px" ><%=ann_content%></textarea>	  			
	  			</td>
	  			
	  			<td style="<%=style1%>">公告类型&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<select id="ann_type" name="ann_type" style="width: 80px;" >
	  				 <option selected="selected"></option>	
	  				 <option value="1">满座</option>
	  				 <option value="2">优惠</option>
	  				 <option value="3">其他</option>
	  				</select>	  				
	  			</td>
	  		</tr>
	  		
	  		<tr>
	  			<td style="<%=style1%>">开始时间&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="ann_begin_time_d" name="ann_begin_time_d" value="<%=ann_begin_time_d%>" style="<%=style2%>" readonly="readonly" onclick="calendar.show(this)" >
	  				<select id="ann_begin_time_t" name="ann_begin_time_t" style="width: 80px;" >
			  		  <option selected="selected"></option>
			  		  <%
			  		  String value;
			  		  String text;
			  		  String value_half;
			  		  String text_half;
					  for(int n = 0; n < 24; ++n) {
						  String t = String.valueOf(n);					  
						  value = t + ":" + "00";
						  text = t + "时";
						  
						  value_half = t + ":" + "30";
						  text_half = " " + t + "时" + "30分";
					  %>
					  <option 
					    value="<%=value%>"><%=text%>
					  </option>
					  <option 
					    value="<%=value_half%>"><%=text_half%>
					  </option>
					  <%}%>				   
		  			</select>	  			
	  			</td>
	  			
	  			<td style="<%=style1%>">结束时间&nbsp;&nbsp;&nbsp;</td>
	  			<td>
	  				<input type="text" id="ann_end_time_d" name="ann_end_time_d" value="<%=ann_end_time_d%>" style="<%=style2%>" readonly="readonly" onclick="calendar.show(this)" >	  			
	  				<select id="ann_end_time_t" name="ann_end_time_t" style="width: 80px;" >
			  		  <option selected="selected"></option>
			  		  <%		
					  for(int n = 0; n < 24; ++n) {
						  String t = String.valueOf(n);					  
						  value = t + ":" + "00";
						  text = t + "时";
						  
						  value_half = t + ":" + "30";
						  text_half = " " + t + "时" + "30分";
					  %>
					  <option 
					    value="<%=value%>"><%=text%>
					  </option>
					  <option 
					    value="<%=value_half%>"><%=text_half%>
					  </option>
					  <%}%>				   
		  			</select>
	  			</td>	  			
	  		</tr>
	  	</table>
	  	
	  	<input type = "hidden" id="business_id" name = "business_id" value="<%=business_id%>">
	  	<input type = "hidden" id="ann_state" name = "ann_state" >
	  	<input type = "hidden" id="ann_begin_time" name = "ann_begin_time">
	  	<input type = "hidden" id="ann_end_time" name = "ann_end_time">
	  	
	  	<input type = "hidden" id="ANNOUNCE_TYPE" name = "ANNOUNCE_TYPE" value="BUSINESS">
	  	<input type = "hidden" id="OPERATE_TYPE" name = "OPERATE_TYPE" value="ADD">
	  	
	  	<table width="100%" border="0" cellpadding="0" cellspacing="0" >
	  		<tr align="center">
	  			<td><input type="submit" value="提交"/></td>
	  		</tr>
		</table>
	  	</form>
	
		
	<SCRIPT LANGUAGE="JavaScript">	
	  	function onload() {
	  		var mode = "<%=mode%>";
	  		if(mode == "mode_add") { //新增模式
	  			document.getElementById("ann_state_1").checked = true;	  			
	  		}
  		}
  		
		function onClickRadio_state(value) {
  			if(value == '0') {
 				document.getElementById("ann_state_0").checked = true;
 				document.getElementById("ann_state_1").checked = false;
 			} else {
 				document.getElementById("ann_state_1").checked = true;
 				document.getElementById("ann_state_0").checked = false; 				
 			} 
  		}
  		
  		function check() {
  		
  			var tmp;
			
			tmp = document.getElementById("ann_type").value;
  			if(tmp == "") {
  				alert("请选择公告类型");
  				return false;
  			}
			
			if(tmp != "1") { //除了满座公告外，都要有标题
	  			tmp = document.getElementById("ann_title").value;
	  			tmp = jQuery.trim(tmp);
	  			if(tmp == "") {
	  	  			alert("请输入公告标题");
	  	  			return false;
	  			}
  			} else {
  				tmp = document.getElementById("ann_title").value;
	  			tmp = jQuery.trim(tmp);
	  			if(tmp == "") document.getElementById("ann_title").value="满座"; //默认标题是满座 数据库中title是必填项
  			}
  			
  			var tmp_d = "";
  			tmp_d = document.getElementById("ann_begin_time_d").value;
  			tmp_d = jQuery.trim(tmp_d);
  			if(tmp_d == "") {
  	  			alert("请选择开始时间");
  	  			return false;
  			}
  			var tmp_t = "";
  			tmp_t = document.getElementById("ann_begin_time_t").value;
  			tmp_t = jQuery.trim(tmp_t);
  			if(tmp_t == "") {
  	  			alert("请选择开始时间");
  	  			return false;
  			}
  			document.getElementById("ann_begin_time").value = tmp_d + " " + tmp_t;
  			
  			
  			tmp_d = document.getElementById("ann_end_time_d").value;
  			tmp_d = jQuery.trim(tmp_d);
  			if(tmp_d == "") {
  	  			alert("请选择结束时间");
  	  			return false;
  			}
  			tmp_t = document.getElementById("ann_end_time_t").value;
  			tmp_t = jQuery.trim(tmp_t);
  			if(tmp_t == "") {
  	  			alert("请选择结束时间");
  	  			return false;
  			}
  			document.getElementById("ann_end_time").value = tmp_d + " " + tmp_t;
  			
  			//状态
  			tmp = "-1";
  			if(document.getElementById("ann_state_1").checked == true) {
  				tmp = "1";
  			} else if (document.getElementById("ann_state_0").checked == true) {
  				tmp = "0";
  			} else { //应该不会出现这种情况
  				alert("请选择公告状态");
  	  			return false;
  			}
  			document.getElementById("ann_state").value = tmp;
  			
  			
  			return true;
  			
  		}
	</SCRIPT>
	</body>
</html>
